package com.onpositive.wiki2.whole.model;

import com.onpositive.wiki2.miner.AbstractWikiPediaVisitor;
import com.onpositive.wiki2.miner.Page;

public final class RedirectStatingVisitor extends
		AbstractWikiPediaVisitor {
	int count = 0;

	public RedirectStatingVisitor() {
	
	}

	@Override
	protected void onPage(Page page) {
		if (page.id > Integer.MAX_VALUE) {
			System.out.println("Caution");			
		}
		String text = page.textContent;
		count++;
		String string = "#REDIRECT [[";
		if (text.startsWith(string)) {
			text = text.substring(string.length());
			int p = text.indexOf("]]");
			text = text.substring(0, p);
			text = text.replace(' ', '_');
			page.redirectTo = text;
			return;
		}
		
		if (count % 1000 == 0) {
			System.out.println(count);
		}
	}
}